//
//  Status.swift
//  SinaWeibo
//
//  Created by 张子国 on 15/11/14.
//  Copyright © 2015年 张子国. All rights reserved.
//

import UIKit

class Status: NSObject {
    //微博创建时间
    var created_at: String?
    //	微博ID
    var id: Int = 0
    //微博信息内容
    var text: String?
    //微博来源
    var source: String?
    
    //定义用户模型的属性
    var user : User?
    
    //配图视图数组
    var pic_urls:[[String : String]]?
    
    //计算型属性

    var imageURLs : [NSURL]? {
        guard let urls = pic_urls else {
            return nil
        }
        var tempArray = [NSURL]()
        for item in urls {
            let url = NSURL(string: item["thumbnail_pic"]!)
            tempArray.append(url!)
        }
        return tempArray
    }
    
    //计算型属性 判断原创微博，转发微博的图片数组
    var pictURLs : [NSURL]? {
        if retweeted_status != nil {
            return retweeted_status?.imageURLs
        }
    
        return imageURLs
    }
    
    
    //被转发的微博子段
    var retweeted_status: Status?


    //KVC赋值
    init(dict : [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String : AnyObject] {
                user = User(dict: dict)
            }
            return
        }
        
        if key == "retweeted_status"{
            if let dict = value as? [String : AnyObject]{
                retweeted_status = Status(dict: dict)
            }
            return
        }
        
        //调用super
        super.setValue(value, forKey: key)
    }
    
    
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
